﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace POS
{
    public partial class Client : Form
    {
        public static Client _main;

        public Client()
        {
            _main = this;
        }

        public void FileReceiveDone()
        {
            MessageBox.Show(this, "File received.");
        }

        public void ConnectDone()
        {
            MessageBox.Show(this, "Connect Success.");
        }

        public static void ConnectToServer()
        {
            //_main = this;

            int port;
            IPAddress ipAddress;

            try
            {
                ipAddress = IPAddress.Parse("192.168.1.13");
            }
            catch
            {
                //MessageBox.Show(Properties.Resources.InvalidAddressMsg);
                return;
            }

            try
            {
                port = Convert.ToInt32(11000);
            }
            catch
            {
                //MessageBox.Show( Properties.Resources.InvalidPortMsg);
                return;
            }

            if (port < 0 || port > 65535)
            {
                //MessageBox.Show(Properties.Resources.InvalidPortMsg);
                return;
            }

            //if (string.IsNullOrEmpty(tbxSavePath.Text))
            //{
            //    MessageBox.Show(Properties.Resources.EmptyPath);
            //    return;
            //}

            Networking.AsynchronousClient.IpAddress = ipAddress;
            Networking.AsynchronousClient.Port = port;
            Networking.AsynchronousClient.FileSavePath = Environment.CurrentDirectory;
            Networking.AsynchronousClient.Client = Client._main;

            Thread threadClient = new Thread(new ThreadStart(Networking.AsynchronousClient.StartClient));
            threadClient.IsBackground = true;
            threadClient.Start();
            //btnConnect.Enabled = false;

        }
    }
}
